package ws

import (
	"sync"
	"time"

	"github.com/gofiber/websocket/v2"

	"publish-manage/internal/model"
)

type Conn struct {
	Agent     *model.Agent
	Conn      *websocket.Conn
	Lock      *sync.Mutex
	Deadline  time.Time
	CloseChan chan struct{}
	MsgChan   chan []byte
	once      sync.Once
}

func (c *Conn) Close() {
	c.once.Do(func() {
		c.Conn.Close()
		close(c.CloseChan)
		close(c.MsgChan)
	})
}
